<?php
namespace Admin\Controller;
use Think\Controller;
class GuestbookController extends BaseController {
    public function index(){
    	$where = array();
        if (I('key')) {
            $where['content'] = array('like','%'.I('key').'%');
        }
		$map['state'] = 1;
    	$this->list = D("Guestbooklist")->Where($where)->Where($map)->order('addtime desc')->Select();
		$this->display();
    }

    public function info(){
        $model = M('Guestbook');
    	$info = $model->where('id='.$id)->find();
        $this->assign('vo',$info);
        $this->display();    
    }
    public function delete($id){
		if (!empty($id)) {
            $model = M("Guestbook");
            $result = $model->delete($id);
            if (false !== $result) {
                $this->success('删除成功！');
            } else {
                $this->error('删除出错！');
            }
        } else {
            $this->error('编号错误！');
        }
    }
    public function state($id){
		$model = M("Guestbook");
        //查询该条信息的state字段值
        $result = $model->find($id);
        //更新字段
        $data['id']=$id;
        if($result['state'] == 1){
          $data['state']=0;
        }
        if($result['state'] == 0){
          $data['state']=1;
        }
        if($model->save($data)){       	
            $this->success('状态更新成功!',U('guestbook/index'),1);
        }else{
            $this->error('状态更新失败',U('guestbook/index'),1);
        }
    }
    
}